package com.offcn.controller;

import com.offcn.service.UserService;
import com.offcn.utils.OAResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/checkLogin")
    @ResponseBody
    public OAResult checkLogin(String uname, String upass, HttpSession session){
        OAResult oaResult=userService.getUserByUnameAndUpass(uname,upass);
        if (oaResult.getStatus()==200){
            session.setAttribute("activeUser",oaResult.getData());
        }
        return oaResult;
    }

    @RequestMapping("/exit")
    public String exit(HttpSession session){
        if (session!=null){
            session.invalidate();
        }
        return "redirect:/login.jsp";
    }
}
